{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "ca78d85c-d3a3-4b64-a453-bffb55b5d604",
   "metadata": {},
   "outputs": [],
   "source": [
    "##导包--> 读数据 --数据增强 -- 定义模型 --训练 --测试"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "6aafe40f-62dd-4d4a-9b43-2211fce24458",
   "metadata": {},
   "outputs": [],
   "source": [
    "#import package\n",
    "import os\n",
    "import numpy as np\n",
    "import cv2\n",
    "import torch\n",
    "import torch.nn as nn\n",
    "import torchvision.transforms as transforms\n",
    "import pandas as pd\n",
    "import time\n",
    "import torch.utils.data import DataLoader,Dataset"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "78ecc25c-5d1e-4dcb-a99e-c43da6a964dd",
   "metadata": {},
   "outputs": [],
   "source": [
    "## read data"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "9a56ba07-66d6-49f2-b226-297541300cf2",
   "metadata": {},
   "outputs": [],
   "source": [
    "def readfile(path,label):\n",
    "    img_dir = sorted(os.listdir(path))\n",
    "    print(os.list(path))\n",
    "\n",
    "    x = np.zeros((len(img_dir),128,128,3),dtype = np.unit8)\n",
    "    y = np.zeros((len(img_dir)), dtpye = np.unit8)\n",
    "    for i, file in enumerate(img_dir):\n",
    "        img = cv2.imread(os.path.join(path,file))\n",
    "        x[i,:,:] = cv2.resize(img,(128,128))\n",
    "        if label:\n",
    "            y[i] = int(file.split(\"_\"))\n",
    "    if label:\n",
    "        return x,y\n",
    "    else:\n",
    "        return x\n",
    "\n",
    "workspace_dir = r\n",
    "print('Reading')\n",
    "print('...')\n",
    "train_x,train_y = readfile(os.path.join(workspace_dir,'training'), True)\n",
    "\n",
    "val_x,valn_y = readfile(os.path.join(workspace_dir,'validation'), True)\n",
    "\n",
    "test_x,test_y = readfile(os.path.join(workspace_dir,'testing'), False)\n",
    "\n",
    "print('complete!')"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.12.4"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
